package logic

import (
	"context"
	"user_srv/models"

	"user_srv/internal/svc"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserListLogic {
	return &UserListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserListLogic) UserList(in *user.UserListRequest) (*user.UserListResponse, error) {
	// todo: add your logic here and delete this line
	var err error
	var u models.User
	u.Status = in.Status

	lists, err := u.UserList()
	if err != nil {
		logx.Error("用户列表查询失败")
		return nil, err
	}
	var userLists []*user.UserList
	for _, v := range lists {
		list := user.UserList{
			UserId:  int64(v.ID),
			Status:  v.Status,
			HeadImg: v.HeadImg,
			Mobile:  v.Mobile,
		}
		userLists = append(userLists, &list)
	}

	return &user.UserListResponse{
		List: userLists,
	}, nil
}
